package com.wyw.learning.authentication.oidc;

import com.wyw.learning.entity.SysUserEntity;
import com.wyw.learning.service.SysUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Title
 * @Description
 * @Author Mr Wu yewen.wu.china@gmail.com
 * @Date 2023/9/19 15:13
 * Update History:
 * Author        Time            Content
 */
@Service
public class MyOidcUserInfoService {

    @Resource
    private SysUserService sysUserService;

    public MyOidcUserInfo loadUser(String username) {
        SysUserEntity sysUserEntity = sysUserService.selectByUsername(username);
        return new MyOidcUserInfo(this.createUser(sysUserEntity));
    }

    private Map<String, Object> createUser(SysUserEntity sysUserEntity) {
        return MyOidcUserInfo.myBuilder()
                .name(sysUserEntity.getName())
                .username(sysUserEntity.getUsername())
                .description(sysUserEntity.getDescription())
                .status(sysUserEntity.getStatus())
                .phoneNumber(sysUserEntity.getUsername())
                .email(sysUserEntity.getUsername() + "@example.com")
                .profile("https://example.com/" + sysUserEntity.getName())
                .address("XXX共和国XX省XX市XX区XXX街XXX号")
                .build()
                .getClaims();
    }

}
